<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="小程序," />





  <link rel="alternate" href="/atom.xml" title="尛孟的博客" type="application/atom+xml" />






<meta name="description" content="微信小程序中就四种类型的文件  js ———- JavaScrip文件,负责页面逻辑  json ——– 项目配置文件，负责窗口颜色等等  wxml ——- 类似HTML文件,负责页面结构  wxss ——- 类似CSS文件,负责页面样式表  小程序的IDE每次编译都会自动整合这四种类型的文件,所以要求都是同名且同路径 每创建一个程序时,在根目录下就会生成app.json , app.js ,">
<meta name="keywords" content="小程序">
<meta property="og:type" content="article">
<meta property="og:title" content="小程序-小程序基本框架">
<meta property="og:url" content="http://yoursite.com/2018/01/10/小程序-小程序基本框架/index.html">
<meta property="og:site_name" content="尛孟的博客">
<meta property="og:description" content="微信小程序中就四种类型的文件  js ———- JavaScrip文件,负责页面逻辑  json ——– 项目配置文件，负责窗口颜色等等  wxml ——- 类似HTML文件,负责页面结构  wxss ——- 类似CSS文件,负责页面样式表  小程序的IDE每次编译都会自动整合这四种类型的文件,所以要求都是同名且同路径 每创建一个程序时,在根目录下就会生成app.json , app.js ,">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://www.z4a.net/images/2018/01/10/1967257-597080e04f2b3e3d.png">
<meta property="og:image" content="http://www.z4a.net/images/2018/01/10/1967257-b2fb6cf009b3f669.png">
<meta property="og:image" content="http://www.z4a.net/images/2018/01/10/_20180110184401.png">
<meta property="og:image" content="http://www.z4a.net/images/2018/01/10/1967257-61458d7fbae5b96d.png">
<meta property="og:updated_time" content="2018-01-16T12:33:00.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="小程序-小程序基本框架">
<meta name="twitter:description" content="微信小程序中就四种类型的文件  js ———- JavaScrip文件,负责页面逻辑  json ——– 项目配置文件，负责窗口颜色等等  wxml ——- 类似HTML文件,负责页面结构  wxss ——- 类似CSS文件,负责页面样式表  小程序的IDE每次编译都会自动整合这四种类型的文件,所以要求都是同名且同路径 每创建一个程序时,在根目录下就会生成app.json , app.js ,">
<meta name="twitter:image" content="http://www.z4a.net/images/2018/01/10/1967257-597080e04f2b3e3d.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"hide","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: 'ZNJ0RM31SP',
      apiKey: '9fae47ade11c769ab25bba4061522c1d',
      indexName: 'for_meng',
      hits: {"per_page":10},
      labels: {"input_placeholder":"输入关键词进行搜索","hits_empty":" 找不到关于 ”${query}“ 的文章 ","hits_stats":" 共找到${hits} 篇文章,花了${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/01/10/小程序-小程序基本框架/"/>




<script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
<link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">


  <title>小程序-小程序基本框架 | 尛孟的博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">尛孟的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">想法总是无法付诸实践…</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/01/10/小程序-小程序基本框架/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="尛孟">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="尛孟的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">小程序-小程序基本框架</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-10T17:12:36+08:00">
                2018-01-10
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/" itemprop="url" rel="index">
                    <span itemprop="name">小程序</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/框架学习/" itemprop="url" rel="index">
                    <span itemprop="name">框架学习</span>
                  </a>
                </span>

                
                
                  ， 
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/小程序/框架学习/基本框架/" itemprop="url" rel="index">
                    <span itemprop="name">基本框架</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/01/10/小程序-小程序基本框架/" class="leancloud_visitors" data-flag-title="小程序-小程序基本框架">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <hr>
<hr>
<h3 id="微信小程序中就四种类型的文件"><a href="#微信小程序中就四种类型的文件" class="headerlink" title="微信小程序中就四种类型的文件"></a>微信小程序中就四种类型的文件</h3><blockquote>
<p> js ———- JavaScrip文件,负责页面逻辑</p>
<p> json ——– 项目配置文件，负责窗口颜色等等</p>
<p> wxml ——- 类似HTML文件,负责页面结构</p>
<p> wxss ——- 类似CSS文件,负责页面样式表</p>
</blockquote>
<p><code>小程序的IDE每次编译都会自动整合这四种类型的文件,所以要求都是同名且同路径</code></p>
<p>每创建一个程序时,在根目录下就会生成app.json , app.js , app.wxss  ,  app.wxml,相当于程序入口main</p>
<blockquote>
<p><em>app.json</em></p>
<blockquote>
<p>app.json文件用来对微信小程序进行全局配置，决定页面文件的路径、窗口表现、设置网络超时时间、设置多 tab 等。</p>
<p>必须要有这个文件，如果没有这个文件，IDE会报错，因为微信框架把这个作为配置文件入口，最简单只需创建这个文件，里面写个大括号就行</p>
</blockquote>
<p><em>app.js</em></p>
<blockquote>
<p>必须要有这个文件，没有也是会报错的！但是这个文件创建一下就行可以什么都不需要写</p>
<p>以后我们可以在这个文件中监听并处理小程序的生命周期函数、声明全局变量。</p>
</blockquote>
<p>app.wxss</p>
<blockquote>
<p>这个文件不是必须的。因为它只是个全局CSS样式文件</p>
<p>页面的WXSS都可以覆盖它的样式</p>
</blockquote>
<p>app.wxml</p>
<blockquote>
<p>这个也不是必须的，而且这个并不是指主界面哦~因为小程序的主页面是靠在JSON文件中配置来决定的</p>
</blockquote>
</blockquote>
<hr>
<hr>
<h2 id="根目录下的-js-WXML-js"><a href="#根目录下的-js-WXML-js" class="headerlink" title="根目录下的 .js  .WXML  .js"></a>根目录下的 .js  .WXML  .js</h2><hr>
<h4 id="app-js"><a href="#app-js" class="headerlink" title="app.js"></a>app.js</h4><h5 id="创建App实例"><a href="#创建App实例" class="headerlink" title="创建App实例"></a>创建App实例</h5><p><code>App() 函数用来注册一个小程序。接受一个 object 参数，其指定小程序的生命周期函数等。</code></p>
<p><img src="http://www.z4a.net/images/2018/01/10/1967257-597080e04f2b3e3d.png" alt="App()参数说明"></p>
<hr>
<h4 id="app-json"><a href="#app-json" class="headerlink" title="app.json"></a>app.json</h4><p><code>json文件负责配置页面路径,tabBar的表现,网络超时时间等</code></p>
<p><img src="http://www.z4a.net/images/2018/01/10/1967257-b2fb6cf009b3f669.png" alt="app.json配置项"></p>
<blockquote>
<p>这里的pages是配置程序的每一个页面的相对路径,页面的创建通过在对应页面的js文件中调用page()来创建</p>
</blockquote>
<hr>
<hr>
<h2 id="创建新的Page页面"><a href="#创建新的Page页面" class="headerlink" title="创建新的Page页面"></a>创建新的Page页面</h2><hr>
<h4 id="js注册页面"><a href="#js注册页面" class="headerlink" title=".js注册页面"></a>.js注册页面</h4><p><code>Page() 函数用来注册一个页面。接受一个 object 参数，其指定页面的初始数据、生命周期函数、事件处理函数等。</code></p>
<p><img src="http://www.z4a.net/images/2018/01/10/_20180110184401.png" alt="page()参数说明"></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">Page(&#123;</span><br><span class="line">  data: &#123;//页面初始数据</span><br><span class="line">    text: "This is page data."</span><br><span class="line">  &#125;,</span><br><span class="line">  onLoad: function(options) &#123;//页面加载   必须是可转json的数据类型</span><br><span class="line">    // Do some initialize when page load.</span><br><span class="line">  &#125;,</span><br><span class="line">  onReady: function() &#123;//渲染完成</span><br><span class="line">    // Do something when page ready.</span><br><span class="line">  &#125;,</span><br><span class="line">  onShow: function() &#123;//页面显示</span><br><span class="line">    // Do something when page show.</span><br><span class="line">  &#125;,</span><br><span class="line">  onHide: function() &#123;//页面隐藏</span><br><span class="line">    // Do something when page hide.</span><br><span class="line">  &#125;,</span><br><span class="line">  onUnload: function() &#123;//页面卸载/销毁</span><br><span class="line">    // Do something when page close.</span><br><span class="line">  &#125;,</span><br><span class="line">  onPullDownRefresh: function() &#123;//用户下拉动作</span><br><span class="line">    // Do something when pull down.</span><br><span class="line">  &#125;,</span><br><span class="line">  onReachBottom: function() &#123;//上拉触底</span><br><span class="line">    // Do something when page reach bottom.</span><br><span class="line">  &#125;,</span><br><span class="line">  onShareAppMessage: function () &#123;//点击右上角转发</span><br><span class="line">   // return custom share data when user share.</span><br><span class="line">  &#125;,</span><br><span class="line">  onPageScroll: function() &#123;//页面滚动时间</span><br><span class="line">    // Do something when page scroll</span><br><span class="line">  &#125;,</span><br><span class="line">  // Event handler.</span><br><span class="line">  viewTap: function() &#123;//页面其他绑定事件处理函数</span><br><span class="line">    this.setData(&#123;</span><br><span class="line">      text: 'Set some data for updating view.'</span><br><span class="line">    &#125;, function() &#123;</span><br><span class="line">      // this is setData callback</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;,</span><br><span class="line">  customData: &#123;</span><br><span class="line">    hi: 'MINA'</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<hr>
<hr>
<h4 id="WXML"><a href="#WXML" class="headerlink" title=".WXML"></a>.WXML</h4><p><code>结合数据绑定、列表渲染、条件渲染、模板、事件、引用，可以构建出页面的结构。</code></p>
<hr>
<ul>
<li><strong>数据绑定</strong></li>
</ul>
<blockquote>
<p>在.js中的data{}中申请的变量都可以在.WXML中使用</p>
<p>在.WXML通过 <strong><em>Mustache 语法(双大括号)</em></strong>就可以使用变量</p>
<p>数据绑定有多种绑定方式—简单绑定,组件属性,控制属性,关键字,运算表达式</p>
<p>除了简单绑定之外其余都需要把<strong><em>双大括号</em></strong>放在<strong><em>双引号</em></strong>之内</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span>&gt;</span> &#123;&#123; 变量名 &#125;&#125; <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br></pre></td></tr></table></figure>
<ul>
<li><h5 id="绑定事件"><a href="#绑定事件" class="headerlink" title="绑定事件"></a>绑定事件</h5><p><img src="http://www.z4a.net/images/2018/01/10/1967257-61458d7fbae5b96d.png" alt="冒泡事件列表"></p>
</li>
</ul>
<blockquote>
<p>因此,如果需要在.WXML中绑定某个事件,那就在标签内添加绑定函数</p>
<p>然后在.js中定义该函数的代码块</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">text</span> <span class="attr">catchtap</span>=<span class="string">"click"</span> <span class="attr">class</span>=<span class="string">"window"</span>&gt;</span>Hello<span class="tag">&lt;/<span class="name">text</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"></span><br><span class="line">....然后在.js文件中就可以定义函数.........</span><br><span class="line"></span><br><span class="line">click:function()&#123;</span><br><span class="line">    console.log("点击了文字");</span><br><span class="line">  &#125;,</span><br></pre></td></tr></table></figure>
<hr>
<h4 id="WXSS"><a href="#WXSS" class="headerlink" title=".WXSS"></a>.WXSS</h4><p><code>用于描述 WXML 的组件样式,用来决定 WXML 的组件应该怎么显示。WXSS 具有 CSS 大部分特性。同时为了更适合开发微信小程序，WXSS 对 CSS 进行了扩充以及修改。与 CSS 相比，WXSS 扩展的特性有：</code></p>
<ul>
<li>尺寸单位(小程序使用<strong><em>rpx</em></strong>,底层根据屏幕宽度进行自适应)</li>
<li>样式导入(用<code>@import+外联样式表绝对路径</code>  可以导入外联样式表)</li>
</ul>
<ul>
<li><p>其他暂时不需要了解太多<a href="http://for_meng.gitee.io/2018/01/12/WXML%E8%A7%86%E5%9B%BE%E5%B1%82/#WXSS" target="_blank" rel="noopener">在视图层的时候再说</a></p>
<hr>
</li>
</ul>
<h4 id="除了这些需要开发者知道的-框架还有其他特点"><a href="#除了这些需要开发者知道的-框架还有其他特点" class="headerlink" title="除了这些需要开发者知道的,框架还有其他特点:"></a>除了这些需要开发者知道的,框架还有其他特点:</h4><blockquote>
<ul>
<li><strong>分包加载</strong>    —  可以优化小程序首次启动的下载时间，以及在多团队共同开发时可以更好的解耦协作</li>
<li><strong>基础库兼容处理</strong>  —  对接口 、参数 、 组件的兼容处理可以查看官方文档</li>
<li><strong>运行机制</strong>    —  [冷启动] 和 [热启动]  以及重启逻辑</li>
</ul>
</blockquote>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/小程序/" rel="tag"># 小程序</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/01/10/NSdate+NSCalendar操作/" rel="next" title="NSdate+NSCalendar操作">
                <i class="fa fa-chevron-left"></i> NSdate+NSCalendar操作
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/01/11/小程序-js逻辑层/" rel="prev" title="小程序-js逻辑层">
                小程序-js逻辑层 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">尛孟</p>
              <p class="site-description motion-element" itemprop="description">与人联系甚少</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">26</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#微信小程序中就四种类型的文件"><span class="nav-number">1.</span> <span class="nav-text">微信小程序中就四种类型的文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#根目录下的-js-WXML-js"><span class="nav-number"></span> <span class="nav-text">根目录下的 .js  .WXML  .js</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#app-js"><span class="nav-number">0.1.</span> <span class="nav-text">app.js</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#创建App实例"><span class="nav-number">0.1.1.</span> <span class="nav-text">创建App实例</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#app-json"><span class="nav-number">0.2.</span> <span class="nav-text">app.json</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建新的Page页面"><span class="nav-number"></span> <span class="nav-text">创建新的Page页面</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#js注册页面"><span class="nav-number">0.1.</span> <span class="nav-text">.js注册页面</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#WXML"><span class="nav-number">0.2.</span> <span class="nav-text">.WXML</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#绑定事件"><span class="nav-number">0.2.1.</span> <span class="nav-text">绑定事件</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#WXSS"><span class="nav-number">0.3.</span> <span class="nav-text">.WXSS</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#除了这些需要开发者知道的-框架还有其他特点"><span class="nav-number">0.4.</span> <span class="nav-text">除了这些需要开发者知道的,框架还有其他特点:</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">尛孟</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.4"></script>



  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("KhsxPkrt4UYiKBnwYFY9zUTN-gzGzoHsz", "a1zezRocQqcmPxlFVdXKrhz9");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
